using UnityEngine;
using System.Collections;

public class LoadingManager : MonoBehaviour {
	
	/// <summary>
	/// 当前载入场景名称
	/// </summary>
	static string NowSceneName;
	
	//异步对象
	AsyncOperation async;
	//进度
	float progress;
	GameObject bar;
		
	/// <summary>
	/// 异步切换场景.
	/// </summary>
	/// <param name='Change'>
	/// 目标场景名称.
	/// </param>
	public static void LoadingScene(string Change)
	{
		NowSceneName = Change;
		Application.LoadLevel("Loading");
	}
	
	// Use this for initialization
	void Start () 
	{
		bar = GameObject.Find("ProgressBar");
		if(NowSceneName != null)
			StartCoroutine(DoingLoading());
	}
	
	IEnumerator DoingLoading()
	{
		async = Application.LoadLevelAsync(NowSceneName);
		yield return async;
	}
	
	// Update is called once per frame
	void Update () 
	{
		if(async != null)
			progress =  async.progress;
		else if(progress < 1)
			progress += 0.01f;
		
		switch(GameData.ScreenRatio)
		{
		case screenRatio.r43:
			bar.transform.localScale = new Vector3((1100)* progress,9f,1f);
			break;
		case screenRatio.r1610:
			bar.transform.localScale = new Vector3((1315)* progress,9f,1f);
			break;
		case screenRatio.r169:
			bar.transform.localScale = new Vector3((1446)* progress,9f,1f);
			break;
		}
	}
}
